package com.proxy.autoclick.checker.http.proxy;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;

import com.proxy.autoclick.common.util.Constants;
import com.proxy.autoclick.common.valueobject.Proxy;
/**
 * Handle checking google host class.
 *
 */
public class ClientExecuteProxyCheckGoogleHost extends ClientExecuteProxy{

	public ClientExecuteProxyCheckGoogleHost(HttpClient httpclient,Proxy myProxy) throws URISyntaxException {
		super(httpclient,myProxy, getHttpGet());
	}
	
	public ClientExecuteProxyCheckGoogleHost(HttpClient httpclient,Proxy myProxy,HttpGet httpGet) throws URISyntaxException {
		super(httpclient,myProxy, httpGet);
	}
	
	private static HttpGet getHttpGet() throws URISyntaxException
	{
		URIBuilder builder = new URIBuilder();
//		builder.setScheme("http").setHost("ajax.googleapis.com").setPath("/ajax/services/search/web")
		builder.setScheme("http").setHost(Constants.GOOGLE_HOST_NAME).setPath("/search")
		    .setParameter("tbm", "isch")
		    .setParameter("hl", "en")
		    .setParameter("source", "hp")
		    .setParameter("biw", "")
		    .setParameter("bih", "")
		    .setParameter("q", "business")
		    .setParameter("btnG", "Search+Images")
		    .setParameter("gbv", "1")
//		    .setParameter("v", "1.0")
//		    .setParameter("hl", "zh-CN")
//		    .setParameter("source", "hp")
//		    .setParameter("aqi", "")
//		    .setParameter("aql", "")
//		    .setParameter("gs_rfai", "")
//		    http://www.google.com/search?tbm=isch&hl=en&source=hp&biw=&bih=&q=XXXXXXX&btnG=Search+Images&gbv=1
		    ;
		URI uri = builder.build();
		HttpGet httpGet = new HttpGet(uri);
//		req.setHeader("User-Agent", 
//					"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");
		return httpGet;
	}


	/**
	 * get valid display string for valid google proxy.
	 */
	public String getValidDisplayString() {
		return " Google (passed)";
	}

	/**
	 * get invalid display string for invalid google proxy.
	 */
	public String getInvalidDisplayString() {
		return " Google (failed)";
	}


	/**
	 * update validForGoogleHost to true for myProxy object
	 * set the update time in myProxy object.
	 */
	public void updateResultByValid(Proxy myProxy) {
		myProxy.setValidForGoogleHost(true);
		myProxy.setUpdateTimeForGoogleHost(new Date());
		mainFrame.setProxyCounterText();
		validProxyQueue.put(myProxy);
	}


	/**
	 * update validForGoogleHost 
	 * to false for myProxy object
	 */
	public void updateResultByInvalid(Proxy myProxy) {
		myProxy.setValidForGoogleHost(false);
	}


	public String[] getRegexString() {
		return Constants.GOOGLE_REGEX_STRING;
	}

	public int getVisitPageDelay() {
		return 200;
	}

	public void setValidOutputMessage(String message) {
		System.out.println(message);
	}

	public void setInValidOutputMessage(String message) {
		System.out.println(message);
	}

}
